﻿var formItems = [
  {
    type: 'listBox',
    category: 'dComponent',
    componentName: 'ListBox',
    name: '列表框',
    icon: 'icon-liebiao',
    config: {
      myStyle: {
        height: '400px'
      },
      label: '列表框'
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'TextInput',
    category: 'dComponent',
    componentName: 'TextInput',
    name: '单行文本',
    icon: 'icon-danhangwenben',
    config: {
      uid: '',
      label: '单行文本',
      other: {
        placeholder: '请输入',
        clearable: true,
        maxLength: -1
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'IPv4Input',
    category: 'dComponent',
    componentName: 'IPv4Input',
    name: 'IP4输入框',
    icon: 'icon-ip',
    config: {
      uid: '',
      label: 'IP4输入框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'NumberInput',
    category: 'dComponent',
    componentName: 'NumberInput',
    name: '数字输入框',
    icon: 'icon-zhengshu',
    config: {
      uid: '',
      label: '数字输入框',
      other: {
        placeholder: '请输入',
        step: 1,
        precision: 0,
        min: -Infinity,
        max: Infinity
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'RadioInput',
    category: 'dComponent',
    componentName: 'RadioInput',
    name: '单选框',
    icon: 'icon-radio',
    config: {
      uid: '',
      label: '单选框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'SelectInput',
    category: 'dComponent',
    componentName: 'SelectInput',
    name: '下拉选框',
    icon: 'icon-shuxingkongjian',
    config: {
      uid: '',
      label: '下拉选框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'SwitchInput',
    category: 'dComponent',
    componentName: 'SwitchInput',
    name: '开关',
    icon: 'icon-38kaiguanguan1',
    config: {
      uid: '',
      label: '开关',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'DatePicker',
    category: 'dComponent',
    componentName: 'DatePicker',
    name: '日期控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '日期',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'DateTimePicker',
    category: 'dComponent',
    componentName: 'DateTimePicker',
    name: '日期时间控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '日期时间',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'TimePicker',
    category: 'dComponent',
    componentName: 'TimePicker',
    name: '时间控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '时间',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'YearPicker',
    category: 'dComponent',
    componentName: 'YearPicker',
    name: '年度控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '年度',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'MonthPicker',
    category: 'dComponent',
    componentName: 'MonthPicker',
    name: '月份控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '月份',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'DateRangePicker',
    category: 'dComponent',
    componentName: 'DateRangePicker',
    name: '日期区间控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '日期区间',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'DateTimeRangePicker',
    category: 'dComponent',
    componentName: 'DateTimeRangePicker',
    name: '日期时间区间控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '日期时间区间',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'MonthRangePicker',
    category: 'dComponent',
    componentName: 'MonthRangePicker',
    name: '月份区间控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '月份区间',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'TimeRangePicker',
    category: 'dComponent',
    componentName: 'TimeRangePicker',
    name: '时间区间控件',
    icon: 'icon-shijianriqi',
    config: {
      uid: '',
      label: '时间区间',
      other: {
        placeholder: '请输入',
        clearable: true
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'EditTable',
    category: 'dComponent',
    componentName: 'EditTable',
    name: '可编辑表格',
    icon: 'icon-biaoge',
    config: {
      uid: '',
      label: '',
      isEnable: true,
      showLabel: false,
      allowChild: true, // 是否允许挂子控件
      children: [], // 子控件下是不允许挂载子控件
      other: {
      }
    },
    events: {
      onRowClick: {
        active: true,
        actions: []
      },
      onRowDClick: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'PictureUpload',
    category: 'dComponent',
    componentName: 'PictureUpload',
    name: '图片上传',
    icon: 'icon-icons01',
    config: {
      uid: '',
      label: '图片上传',
      other: {
      }
    },
    events: {
    }
  }, {
    type: 'PicturesUpload',
    category: 'dComponent',
    componentName: 'PicturesUpload',
    name: '多图片上传',
    icon: 'icon-icons01',
    config: {
      uid: '',
      label: '多图片上传',
      other: {
      }
    },
    events: {
    }
  }, {
    type: 'FilesUpload',
    category: 'dComponent',
    componentName: 'FilesUpload',
    name: '多文件上传',
    icon: 'icon-zichanguanli',
    config: {
      uid: '',
      label: '多文件上传',
      other: {
      }
    },
    events: {
    }
  }, {
    type: 'FileUpload',
    category: 'dComponent',
    componentName: 'FileUpload',
    name: '文件上传',
    icon: 'icon-file',
    config: {
      uid: '',
      label: '文件上传',
      other: {
      }
    },
    events: {
    }
  }, {
    type: 'CadecaseSelectInput',
    category: 'dComponent',
    componentName: 'CadecaseSelectInput',
    name: '级联选框',
    icon: 'icon-lianjixuanze',
    config: {
      uid: '',
      label: '级联选框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'PopInput',
    category: 'dComponent',
    componentName: 'PopInput',
    name: '弹框',
    icon: 'icon-biaoge',
    config: {
      uid: '',
      label: '弹框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'MapInput',
    category: 'dComponent',
    componentName: 'MapInput',
    name: '地图经纬度',
    icon: 'icon-ditu',
    config: {
      uid: '',
      label: '地图经纬度',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'MDInput',
    category: 'dComponent',
    componentName: 'MDInput',
    name: 'MD输入框',
    icon: 'icon-buju',
    config: {
      uid: '',
      label: 'MD输入框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'JSONInput',
    category: 'dComponent',
    componentName: 'JSONInput',
    name: 'JSON输入框',
    icon: 'icon-json',
    config: {
      uid: '',
      label: 'JSON输入框',
      other: {
      }
    },
    events: {
      onChange: {
        active: true,
        actions: []
      }
    }
  }
]

var layoutItems = [
  {
    type: 'grid',
    category: 'dComponent',
    componentName: 'GridLayout',
    name: '格栅布局',
    icon: 'icon-buju',
    config: {
      label: '格栅布局',
      showLabel: false,
      allowChild: true, // 是否允许挂子控件
      children: [], // 子控件下是不允许挂载子控件
      other: {
        gutter: 1
      }
    },
    events: {
    }
  }, {
    type: 'tabs',
    category: 'dComponent',
    componentName: 'Tabs',
    name: '选项卡',
    icon: 'icon-bootstrap_tabs',
    config: {
      label: '选项卡',
      showLabel: false,
      allowChild: true, // 是否允许挂子控件
      children: [], // 子控件下是不允许挂载子控件
      other: {
      }
    },
    events: {
    }
  }, {
    type: 'form',
    category: 'dComponent',
    componentName: 'Form',
    name: '表单',
    icon: 'icon-fuwenben',
    config: {
      label: '表单',
      showLabel: false,
      allowChild: true, // 是否允许挂子控件
      children: [], // 子控件下是不允许挂载子控件
      other: {
        labelPosition: 'left',
        labelWidth: '80px'
      }
    },
    events: {
    }
  }
]

var otherItems = [
  {
    type: 'Button',
    category: 'dComponent',
    componentName: 'Button',
    name: '按钮',
    icon: 'icon-anniu',
    config: {
      other: {
        type: 'primary',
        leftIcon: '',
        rightIcon: '',
        text: '查询'
      }
    },
    events: {
      onClick: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'LinkButton',
    category: 'dComponent',
    componentName: 'LinkButton',
    name: '链接',
    icon: 'icon-jilianxuanze',
    config: {
      other: {
        type: 'primary',
        leftIcon: '',
        rightIcon: '',
        text: '查询',
        underline: true
      }
    },
    events: {
      onClick: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'MetaQuery',
    category: 'dComponent',
    componentName: 'MetaQuery',
    name: '元数据表单',
    icon: 'icon-biaoge',
    config: {
      uid: '',
      label: '',
      showLabel: false,
      allowChild: true, // 是否允许挂子控件
      children: [], // 子控件下是不允许挂载子控件
      other: {
      }
    },
    events: {
      onRowClick: {
        active: true,
        actions: []
      },
      onRowDClick: {
        active: true,
        actions: []
      }
    }
  }, {
    type: 'MetaTreeQuery',
    category: 'dComponent',
    componentName: 'MetaTreeQuery',
    name: '元数据树表单',
    icon: 'icon-liebiao',
    config: {
      uid: '',
      label: '',
      showLabel: false,
      allowChild: true, // 是否允许挂子控件
      children: [], // 子控件下是不允许挂载子控件
      other: {
      }
    },
    events: {
      onRowClick: {
        active: true,
        actions: []
      },
      onRowDClick: {
        active: true,
        actions: []
      }
    }
  }
]

function formatList (list, category2) {
  for (let i = 0; i < list.length; i++) {
    var item = list[i]
    if (Object.keys(item).indexOf('value') === -1) {
      item.value = null
    }
    if (Object.keys(item).indexOf('myData') === -1) {
      item.myData = []
    }
    if (Object.keys(item).indexOf('config') === -1) {
      item.config = {
        uid: '',
        isShow: true,
        isEnable: true,
        isRequired: false,
        myStyle: {},
        dataKey: '',
        label: '组件',
        labelSpan: 4,
        showLabel: true,
        allowChild: false, // 是否允许挂子控件
        children: []
      }
    }
    // config
    if (Object.keys(item.config).indexOf('uid') === -1) {
      item.config.uid = ''
    }
    if (Object.keys(item.config).indexOf('isShow') === -1) {
      item.config.isShow = true
    }
    if (Object.keys(item.config).indexOf('isEnable') === -1) {
      item.config.isEnable = true
    }
    if (Object.keys(item.config).indexOf('isRequired') === -1) {
      item.config.isRequired = false
    }
    if (Object.keys(item.config).indexOf('myStyle') === -1) {
      item.config.myStyle = {}
    }
    if (Object.keys(item.config).indexOf('dataKey') === -1) {
      item.config.dataKey = ''
    }
    if (Object.keys(item.config).indexOf('label') === -1) {
      item.config.label = '组件'
    }
    if (Object.keys(item.config).indexOf('labelSpan') === -1) {
      item.config.labelSpan = 4
    }
    if (Object.keys(item.config).indexOf('showLabel') === -1) {
      item.config.showLabel = true
    }
    if (Object.keys(item.config).indexOf('allowChild') === -1) {
      item.config.allowChild = false
    }
    if (Object.keys(item.config).indexOf('children') === -1) {
      item.config.children = []
    }
    if (Object.keys(item.config).indexOf('other') === -1) {
      item.config.other = {}
    }
    if (Object.keys(item.config).indexOf('category2') === -1) {
      item.config.category2 = category2
    }
  }
  return list
}

export const formComponents = formatList(formItems, 'form')
export const layoutComponents = formatList(layoutItems, 'layout')
export const otherComponents = formatList(otherItems, 'other')
